package practice2;


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class P8604 {

    private static int n;       //站点数

    private static int m;       //通道数

    private static int u;

    private static int v;

    private static int df = Integer.MAX_VALUE;      //危险系数

    private static Map<Integer,Boolean> isGo = new HashMap<>();       //记录该站点有没有走过,key为节点，value表示该节点是否走过

    private static Map<Integer,String> map = new HashMap<>();   //记录通道的图,key为节点,value为与该节点相连的节点的拼接字符串

    public static void dfs(int point,int step){         //point为当前节点,step为当前走过的节点数
        if(point == v){                 //到达目标节点
            df = Math.min(df,step-2);
            return;
        }
        String value = map.get(point);
        String[] strings = value.split(",");
        if(strings.length == 1 && point != u){       //走到顶了没路了(排除调最开始的节点)
            return;
        }
        for(int i=0;i<strings.length;i++){
            int next = Integer.parseInt(strings[i]);
            if(!isGo.get(next)){
                isGo.put(next,true);
                dfs(next,step+1);
                isGo.put(next,false);   //回溯
            }
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();   //站点数
        m = sc.nextInt();   //通道数
        for(int i=0;i<m;i++){
            int u = sc.nextInt();
            int v = sc.nextInt();
            String v1 = map.get(u);
            String v2 = map.get(v);
            if(v1 == null && v2 == null){       //构成一个map集合，存放各个节点(key)与其相邻的节点字符串拼接(value)
                map.put(u,v+"");
                map.put(v,u+"");
            }else if(v1 == null && v2 !=null){
                map.put(u,v+"");
                map.put(v,v2+","+u);
            }else if(v1 != null && v2 == null){
                map.put(u,v1+","+v);
                map.put(v,u+"");
            }else {
                map.put(u,v1+","+v);
                map.put(v,v2+","+u);
            }
            isGo.put(u,false);
            isGo.put(v,false);
        }
        u = sc.nextInt();
        v = sc.nextInt();
        isGo.put(u,true);
        dfs(u,1);
        if(df == Integer.MAX_VALUE){
            System.out.println(-1);
        }else {
            System.out.println(df);
        }
    }
}
